package com.xmgps.bdt.domain.bokun.prototol;

import com.xmgps.bdt.infrastructure.util.BcdUtil;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.util.LinkedList;
import java.util.List;

/**
 * @author wangzezhou
 * @date 2022/6/2
 */
@Data
class CMD {

    /** 终端的ID标识序列 */
    private String devImei;

    /** 协议类型 */
    private byte cmdId;

    /** 加密方式，目前总是为 0x00 */
    private byte encryptCode;

    /** 消息体长度（不超过1024） */
    private short bodyLength;

    private ByteBuf body;

    static CMD readCreate(ByteBuf datagram){

        CMD cmd = new CMD();

        cmd.devImei = BcdUtil.convertToString(datagram,8);
        cmd.cmdId = (datagram.readByte());
        int bodyLength = datagram.readShort();
        cmd.body = datagram.readBytes(bodyLength);

        return cmd;
    }
}
